//
//  YRefreshHeader.swift
//  NightNews
//
//  Created by 薛永伟 on 2019/8/21.
//  Copyright © 2019 XueYongWei. All rights reserved.
//

import UIKit

class YRefreshHeader: MJRefreshStateHeader {

    fileprivate  lazy var aniView: UIView = {
        let view = UIView()
//            LOTAnimationView.init(name: "simpleLoader")
//        UIView()
//        view.loopAnimation = true
        view.contentMode = UIView.ContentMode.scaleAspectFill
        view.backgroundColor = .white
        return view
    }()
    
    fileprivate lazy var holderView: UIView = {
        let view = UIView()
        view.backgroundColor = .white
        return view
    }()
    
    fileprivate lazy var msgBtn: UIButton = {
        let view = UIButton.init(type: .custom)
        view.setTitleColor(UIColor.init(rgb: 0x0E0E0E), for: .normal)
        view.titleLabel?.font = UIFont.systemFont(ofSize: 12, weight: .regular)
        view.isHidden = true
        view.backgroundColor = UIColor.init(rgb: 0xEDEDED)
        view.layer.cornerRadius = 12
        return view
    }()
    
    
    override func prepare() {
        
        super.prepare()
        
        addSubview(holderView)
        holderView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        holderView.addSubview(aniView)
        aniView.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
            make.width.equalTo(120.scaleLength)
            make.height.equalTo(24)
        }
        
        holderView.addSubview(msgBtn)
        msgBtn.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
            make.width.equalTo(120.scaleLength)
            make.height.equalTo(24)
        }
        
//        aniView.play()
    }
    
    override func placeSubviews() {
        
        super.placeSubviews()
        
        
    }

    func showMsg(_ msg:NSAttributedString) {
        msgBtn.isHidden = false
        msgBtn.setAttributedTitle(msg, for: .normal)
    }
    
    override var state: MJRefreshState{
        
        willSet{
            guard state != newValue else {
                return
            }
            super.state = state
        }
        
        didSet{
            
            if state == .refreshing {
                self.holderView.isHidden = false
            }else{
                self.holderView.isHidden = true
                self.msgBtn.isHidden = true
            }
        }
    }
}

//MARK: - --------------类--------------
extension YRefreshHeader {
    
    
}
//MARK: - --------------响应事件--------------

//MARK: - --------------数据请求--------------

//MARK: - --------------辅助方法--------------

//MARK: - --------------驱动UI--------------
